package com.arlen.centre.kafkaService;

import com.arlen.common.constant.KafkaTopicConstant;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.OpenOption;
import java.util.Map;
import java.util.Optional;

@Service
public class SaveWxMapperService {

    private static final String topic = KafkaTopicConstant.SAVE_WX_MATTER.getTopic();



    @KafkaListener(topics = {"save_wx_matter"})
    @KafkaHandler
    private void saveWxMapper(ConsumerRecord<String,String> consumerRecord){
        Optional<ConsumerRecord> optional = Optional.ofNullable(consumerRecord);
        if (optional.isPresent()){
            String value = consumerRecord.value();
            ObjectMapper objectMapper = new ObjectMapper();
            Map map = null;
            try {
                 map = objectMapper.readValue(value, Map.class);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (map!=null){
                String picUrl = map.get("PicUrl").toString();
                String msgType = map.get("MsgType").toString();
                String mediaId = map.get("MediaId").toString();

            }
        }

    }





}
